// David Ciani <dciani@ucsc.edu>
// $Id: Deck.java 4 2011-03-08 11:27:57Z dciani@davidciani.com $

import java.util.*;

class Deck {
    // fields
    private Stack<Card> deck; 

    // methods
    public Deck(long seed) {
        deck = new Stack<Card>();
        for(int cardi=0; cardi<52; cardi++)
            deck.push(new Card(cardi));

        this.shuffle(seed);
    }

    public Deck() {
        this((new Date()).getTime());
    }

    public Card draw() {
        return this.deck.pop();
    }

    private void shuffle(long seed) {
        Random r = new Random(seed);
        for(int cardi=0; cardi<52; cardi++) {
            int randi = r.nextInt(52);
            Card tmp = this.deck.get(randi);
            this.deck.set(randi, this.deck.get(cardi));
            this.deck.set(cardi, tmp);
        }
    }
}
